export default class FeatureUtil {
  static getFeatures() {
    const featureContext = this.context()
    return featureContext.keys().reduce((r, a) => {
      const name = a.match(/\.\/([^\/]+)/)[1]
      if (!r.includes(name)) {
        r.push(name)
      }
      return r
    }, [])
  }

  static context() {
    return require.context('@/feature', true, /\.js$/)
  }

  // 特征初始化
  static init() {
    const featureContext = this.context()
    featureContext.keys().forEach(key => {
      if (key.endsWith('__init__.js')) {
        featureContext(key)
      }
    })
  }
}
